package com.atguigu.command;

import com.atguigu.command.tv.TvOffCommand;
import com.atguigu.command.tv.TvOnCommand;
import com.atguigu.command.tv.TvReceiver;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description:
 * @create: 2022-03-01 23:08
 **/
public class Client {

    public static void main(String[] args) {
        //使用命令设计模式，完成通过遥控器对电灯的操作

        //创建电灯的对象（接收者）
        LightReceiver lightReceiver = new LightReceiver();

        //创建电灯相关的开关命令
        LightOnCommand lightOnCommand = new LightOnCommand(lightReceiver);
        LightOffCommand lightOffCommand = new LightOffCommand(lightReceiver);

        //需要一个遥控器
        RemoteController remoteController = new RemoteController();
        //给我们的遥控器设置命令，比如 no = 0, 是电灯开和关的操作
        remoteController.setCommand(0, lightOnCommand, lightOffCommand);

        System.out.println("------------按下灯的开按钮-----------");
        remoteController.onButtonWasPushed(0);
        System.out.println("------------按下灯的关按钮-----------");
        remoteController.offButtonWasPushed(0);
        System.out.println("------------按下灯的撤销按钮-----------");
        remoteController.undoButtonWasPushed(0);

        System.out.println("-----------------------验证命令模式的优点，新增TV电视机类型的产品（只需增加产品的接收者和中间层的命令，就可以完成调用）-----------------------");

        TvReceiver tvReceiver = new TvReceiver();
        TvOnCommand tvOnCommand = new TvOnCommand(tvReceiver);
        TvOffCommand tvOffCommand = new TvOffCommand(tvReceiver);
        //给我们的遥控器设置命令，比如 no = 1, 是电视机开和关的操作
        remoteController.setCommand(1, tvOnCommand, tvOffCommand);

        System.out.println("------------按下电视机的开按钮-----------");
        remoteController.onButtonWasPushed(1);
        System.out.println("------------按下电视机的关按钮-----------");
        remoteController.offButtonWasPushed(1);
        System.out.println("------------按下电视机的撤销按钮-----------");
        remoteController.undoButtonWasPushed(1);


    }
}
